<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>安装程序</title>
    <script src="/admin_static/jquery.js"></script>
</head>

<body>
    <div class="app">
        <header>
            <img src="/ducksite.png" alt="logo" />
            <h2>安装程序</h2>
        </header>
        <main>请稍后...</main>
        <footer>
            <div class="progress">
                <div class="progress-bar">
                    <div class="progress-bar-block"></div>
                </div>
                <div class="progress-texts"></div>
            </div>
            <p>Copyright (c) 2023-present StarDreamNet</p>
        </footer>
    </div>
    <script>
        $(document).ready(function () {
            const main = $("main");
            const process = [{
                title: "准备安装",
                func(next) {
                    main.html("");

                    var ready = $("<div>").addClass("ready");
                    var title = $("<h2>").text("欢迎使用 DuckSite 安装向导！")
                    var start = $("<button>").text("开始安装");

                    start.on("click", function () {
                        next();
                    });

                    ready.append(title, start);
                    main.append(ready);
                }
            }, {
                title: "正在安装",
                func(next, error) {
                    main.html("");

                    var d1 = $("<span>").text("安装中...");
                    $.ajax({
                        url: "/install/install",
                        success: function (data) {
                            if (data.code == 200) {
                                d1.text("安装成功！");
                                next();
                            }
                            else {
                                d1.text("安装失败！");
                                error();
                            }
                        },
                        error: function () {
                            d1.text("安装失败！");
                            error();
                        }
                    });
                }
            }, {
                title: "安装完成",
                func() {
                    main.html("");

                    var ready = $("<div>").addClass("ready");
                    var title = $("<h2>").text("感谢使用 DuckSite 安装向导！")
                    var start = $("<button>").text("开始使用");

                    start.on("click", function () {
                        window.location.href = "/";
                    });
                }
            }];

            var current = -1;

            function next_() {
                current++;
            }
            function error_() {

            }
            function init_() {
                process.forEach(({ title }) => {
                    $(".progress-texts").append($("<span>").text(title));
                })
            }
        });
    </script>
</body>

</html>